/**
 * English Length Unit Tests
 * Tests convert and toUnit for each Unit Type
 */

package cmsc495.mach2.test.unit.english;

import cmsc495.mach2.unit.english.EnglishLengthUnit;
import junit.framework.TestCase;

/**
 * @author Michael Swann
 */

public class EnglishLengthUnitValidation extends TestCase {

	// Amount of Error Allowed
	private static final double					DELTA				= 0.01;

	private static final double					INCHES_VALUE		= 63360.0;
	private static final double					FEET_VALUE			= 5280.0;
	private static final double					YARDS_VALUE			= 1760.0;
	private static final double					MILES_VALUE			= 1.0;
	private static final double					METERS_VALUE		= 1609.3440006146;

	private static final double					values[]			= { INCHES_VALUE, FEET_VALUE, YARDS_VALUE, MILES_VALUE, METERS_VALUE };
	private static final EnglishLengthUnit[]	englishLengthUnits	= EnglishLengthUnit.values();

	public EnglishLengthUnitValidation() {
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#convert(double, mach2convert.englishunit.EnglishLengthUnit)}
	 * .
	 */
	public final void testConvert() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			for (int j = 0; j < englishLengthUnits.length; j++) {
				double result = englishLengthUnits[i].convert(values[j], englishLengthUnits[j]);
				System.out.println("ASSERT: " + values[i] + " = " + result + " " + englishLengthUnits[i] + ".convert(" + values[j] + ", " + englishLengthUnits[j] + "))");
				assertEquals(values[i], result, DELTA);
			}
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#toInches(double)}.
	 */
	public final void testToInches() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			double result = englishLengthUnits[i].toInches(values[i]);
			System.out.println("ASSERT: " + INCHES_VALUE + " = " + result + " " + englishLengthUnits[i] + ".toInches(" + values[i] + ") ");
			assertEquals(INCHES_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#toFeet(double)}.
	 */
	public final void testToFeet() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			double result = englishLengthUnits[i].toFeet(values[i]);
			System.out.println("ASSERT: " + FEET_VALUE + " = " + result + " " + englishLengthUnits[i] + ".toFeet(" + values[i] + ") ");
			assertEquals(FEET_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#toYards(double)}.
	 */
	public final void testToYards() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			double result = englishLengthUnits[i].toYards(values[i]);
			System.out.println("ASSERT: " + YARDS_VALUE + " = " + result + " " + englishLengthUnits[i] + ".toYards(" + values[i] + ") ");
			assertEquals(YARDS_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#toMiles(double)}.
	 */
	public final void testToMiles() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			double result = englishLengthUnits[i].toMiles(values[i]);
			System.out.println("ASSERT: " + MILES_VALUE + " = " + result + " " + englishLengthUnits[i] + ".toMiles(" + values[i] + ") ");
			assertEquals(MILES_VALUE, result, DELTA);
		}
	}

	/**
	 * Test method for
	 * {@link mach2convert.englishunit.EnglishLengthUnit#toMeters(double)}.
	 */
	public final void testToMeters() {
		for (int i = 0; i < englishLengthUnits.length; i++) {
			double result = englishLengthUnits[i].toMeters(values[i]);
			System.out.println("ASSERT: " + METERS_VALUE + " = " + result + " " + englishLengthUnits[i] + ".toMeters(" + values[i] + ") ");
			assertEquals(METERS_VALUE, result, DELTA);
		}
	}

}